<?
        $params[sid] = $sid;
        $params[action] = "sales";
        $url = "$baseURL/$webDIR/?".encode_params($params);

        if($errorMsg) echo "<center>$errorMsg<center>";
        $errorMsg = "";
        
        if(!$details[start]) $details[start] = get_signup_date($id);
        if(!$details[end]) $details[end] = date("Y-m-d");
	
	$date = explode("-",$details[start]);
	$syear = $date[0];
	$smonth = $date[1];
	$sday = $date[2];

        $date = explode("-",$details[end]);
        $eyear = $date[0];
        $emonth = $date[1];
        $eday = $date[2];

        
        $data =  list_payment_history($id,'details_normal',$details);
	$refunds = list_payment_history($id,'details_refund',$details);
?>

<TABLE border=0 class='bTable' cellspacing='0'>
<form action='<? echo $url; ?>' method='POST'>
	<tr>
		<th>Type</th>
		<th>Day</th>
		<th>Month</th>
		<th>Year</th>
	</tr>
	<tr>
		<td>Start report date</td>
		<td>
			<select name='sday'>
			<?
				$opt = "<option value=''></option>";
				for($i=1;$i<=31;$i++){
					if($i<10) $opt .= "<option value='0$i'>$i</option>";
					else $opt .= "<option value='$i'>$i</option>";
				}
				$newopt = str_replace("'$sday'","$sday selected",$opt);
				echo $newopt;
			?>
			</select>
		</td>
		<td>
			<select name='smonth'>
			<?
				$opt = "<option value=''></option>";
				for($i=1;$i<=12;$i++){
					$m = date ("F", mktime(0,0,0,$i,2,2000));
						if($i<10) $opt .= "<option value='0$i'>$m</option>";
						else $opt .= "<option value='$i'>$m</option>";
				}
				$newopt = str_replace("'$smonth'","$smonth selected",$opt);
				echo $newopt;
			?>			
			</select>
		</td>		
		<td>
			<select name='syear'>
			<?
				$opt = "<option value=''></option>";
				for($i=2002;$i<=date("Y");$i++){
					if($i<10) $opt .= "<option value='0$i'>$i</option>";
					else $opt .= "<option value='$i'>$i</option>";

				}
				$newopt = str_replace("'$syear'","$syear selected",$opt);
				echo $newopt;
			?>			
			</select>
		</td>		
	</tr>
	<tr>
		<td>End report date</td>

		<td>
			<select name='eday'>
			<?
				$opt = "<option value=''></option>";
				for($i=1;$i<=31;$i++){
					if($i<10) $opt .= "<option value='0$i'>$i</option>";
					else $opt .= "<option value='$i'>$i</option>";
				}
				$newopt = str_replace("'$eday'","$eday selected",$opt);
				echo $newopt;
			?>
			</select>
		</td>
		<td>
			<select name='emonth'>
			<?
				$opt = "<option value=''></option>";
				for($i=1;$i<=12;$i++){
					$m = date ("F", mktime(0,0,0,$i,2,2000));
						if($i<10) $opt .= "<option value='0$i'>$m</option>";
						else $opt .= "<option value='$i'>$m</option>";
				}
				$newopt = str_replace("'$emonth'","$emonth selected",$opt);
				echo $newopt;
			?>			
			</select>
		</td>		
		<td>
			<select name='eyear'>
			<?
				$opt = "<option value=''></option>";
				for($i=2003;$i<=date("Y");$i++){
					if($i<10) $opt .= "<option value='0$i'>$i</option>";
					else $opt .= "<option value='$i'>$i</option>";

				}
				$newopt = str_replace("'$eyear'","$eyear selected",$opt);
				echo $newopt;
			?>			
			</select>
		</td>	

	</tr>
	<tr>
		<td colspan='5' align='center'>
			<input type='submit' value='View report for this period'>
		</td>
	</tr>
</form>
</TABLE>

<br>
<TABLE border=0 class='bTable' cellspacing='0'>

<tr>
	<th>Type</th>
	<th>Units</th>
	<th>Retail</th>
	<th>Wholesale</th>
	<th>Profit</th>
</tr>
<tr>
	<td>Domain registrations</td>
	<td><? echo ($data[domain][count])?$data[domain][count]:0; ?></td>
	<td>$<? echo ($data[domain][price])?$data[domain][price]:0; ?></td>
	<td>$<? echo ($data[domain][real_price])?$data[domain][real_price]:0; ?></td>
	<td>$<? echo ($data[domain][profit])?$data[domain][profit]:0; ?></td>
</tr>
<tr>
	<td>Plan registrations</td>
	<td><? echo ($data[plan][count])?$data[plan][count]:0; ?></td>
	<td>$<? echo ($data[plan][price])?$data[plan][price]:0; ?></td>
	<td>$<? echo ($data[plan][real_price])?$data[plan][real_price]:0; ?></td>
	<td>$<? echo ($data[plan][profit])?$data[plan][profit]:0; ?></td>
</tr>
<tr>
        <td>Domain refunds</td>
        <td colspan='5'><? echo ($refunds[domain][count])?$refunds[domain][count]:0; ?></td>
</tr>
<tr>
        <td>Plan refunds</td>
        <td colspan='5'><? echo ($refunds[plan][count])?$refunds[plan][count]:0; ?></td>
</tr>
<tr>
	<td>
		Total proffit:
	</td>
	<td colspan='5'>
		$ <? echo ($data[domain][profit]+$data[plan][profit]); ?>
	</td>
</tr>
</TABLE>


